"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/2/13 15:52
@Description :  python推导式
 列表推导式
"""
# 过滤掉长度小于或等于3的字符串列表，并将剩下的转换成大写字母：
names = ['Bob', 'Tom', 'alice', 'Jerry', 'Wendy', 'Smith']
new_name = []
for name in names:
    if len(name) > 3:
        new_name.append(name.upper())

print(new_name)

#  推导式   表达式的结果 就是列表中的元素
# new_name = [name.upper() for name in names]
new_name = [name.upper() for name in names if len(name) > 3]
print(new_name)

#  str  hello
str_info = 'hello'
new_str_list = [str.upper() for str in str_info]
print(new_str_list)

# 字典推导式
# 使用字符串及其长度创建字典：
list_demo = ['Google', 'Runoob', 'Taobao']

# str_dict = {key: len(key) for key in list_demo}
str_dict = {key: len(key) for key in list_demo if key == 'Taobao'}
print(str_dict)

# 集合推导式
set_num = {i ** 2 for i in range(1, 4)}
print(set_num)

# 元组推导式  生成器  generator
tuple_num = (i ** 2 for i in range(1, 4))
#  通过tuple函数将生成器对象 转换为元组
tuple_num_result = tuple(tuple_num)
print(tuple_num_result, type(tuple_num_result))
